package com.ruoyi.gbase.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gbase.domain.TProcCron;
import com.ruoyi.gbase.service.ITProcCronService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 存储过程任务定义Controller
 * 20201204 暂时作废，这个不用了
 * 
 * @author yys
 * @date 2020-11-09
 *
 */
@Controller
@RequestMapping("/gbase/CRON")
public class TProcCronController extends BaseController
{
    private String prefix = "gbase/CRON";

    @Autowired
    private ITProcCronService tProcCronService;


    @RequiresPermissions("gbase:CRON:view")
    @GetMapping()
    public String CRON()
    {
        return prefix + "/CRON";
    }

    /**
     * 根据id执行存储过错
     */
     /* 
    @GetMapping(value={"/call/{id}"})
    public String backupall(@PathVariable("id") int id)
    {
        TProcCron tProcCron = new TProcCron();
        tProcCron = tProcCronService.selectTProcCronById(id);
        String currentDate = DateUtils.getdateYYYYMMDD();
      if(tProcCron!=null){
            logger.info("开始执行存储过程："+tProcCron);
            procUil.executeProc(tProcCron.getProcname(),tProcCron.getParentprocname(),currentDate,
                    tProcCron.getProcchecktables(),tProcCron.getProccallsql(),tProcCron.getRecyleflg());
        }

        return prefix + "/result";
    }
    */
    /**
     * 查询存储过程任务定义列表
     */
    @RequiresPermissions("gbase:CRON:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TProcCron tProcCron)
    {
        startPage();
        List<TProcCron> list = tProcCronService.selectTProcCronList(tProcCron);
        return getDataTable(list);
    }

    /**
     * 导出存储过程任务定义列表
     */
    @RequiresPermissions("gbase:CRON:export")
    @Log(title = "存储过程任务定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TProcCron tProcCron)
    {
        List<TProcCron> list = tProcCronService.selectTProcCronList(tProcCron);
        ExcelUtil<TProcCron> util = new ExcelUtil<TProcCron>(TProcCron.class);
        return util.exportExcel(list, "CRON");
    }

    /**
     * 新增存储过程任务定义
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存存储过程任务定义
     */
    @RequiresPermissions("gbase:CRON:add")
    @Log(title = "存储过程任务定义", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TProcCron tProcCron)
    {
        return toAjax(tProcCronService.insertTProcCron(tProcCron));
    }

    /**
     * 修改存储过程任务定义
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        TProcCron tProcCron = tProcCronService.selectTProcCronById(id);
        mmap.put("tProcCron", tProcCron);
        return prefix + "/edit";
    }

    /**
     * 修改保存存储过程任务定义
     */
    @RequiresPermissions("gbase:CRON:edit")
    @Log(title = "存储过程任务定义", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TProcCron tProcCron)
    {
        return toAjax(tProcCronService.updateTProcCron(tProcCron));
    }

    /**
     * 删除存储过程任务定义
     */
    @RequiresPermissions("gbase:CRON:remove")
    @Log(title = "存储过程任务定义", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tProcCronService.deleteTProcCronByIds(ids));
    }
}
